package com.zzx.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    /*插入字段填充*/
    @Override
    public void insertFill(MetaObject metaObject) {
        Long time = new Date().getTime();
        Long time2 = Long.valueOf(time.toString().substring(0,10));

        /*填充策略*/
        this.fillStrategy(metaObject,"mgTime",time2);
        this.fillStrategy(metaObject,"addTime",time2);
        this.fillStrategy(metaObject,"updTime",time2);

    }
    /*更新字段填充*/
    @Override
    public void updateFill(MetaObject metaObject) {
        Long time = new Date().getTime();
        Long time2 = Long.valueOf(time.toString().substring(0,10));
        this.fillStrategy(metaObject,"updTime",time2);
    }
}
